package com.ruoyi.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.domain.BaseFriendLink;
import com.ruoyi.service.IBaseFriendLinkService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 友情链接Controller
 * 
 * @author ruoyi
 * @date 2024-05-14
 */
@RestController
@RequestMapping("/webshop/BaseFriendLink")
public class BaseFriendLinkController extends BaseController
{
    @Autowired
    private IBaseFriendLinkService baseFriendLinkService;

    /**
     * 查询友情链接列表
     */
    @PreAuthorize("@ss.hasPermi('webshop:BaseFriendLink:list')")
    @GetMapping("/list")
    public TableDataInfo list(BaseFriendLink baseFriendLink)
    {
        startPage();
        List<BaseFriendLink> list = baseFriendLinkService.selectBaseFriendLinkList(baseFriendLink);
        return getDataTable(list);
    }

    /**
     * 导出友情链接列表
     */
    @PreAuthorize("@ss.hasPermi('webshop:BaseFriendLink:export')")
    @Log(title = "友情链接", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseFriendLink baseFriendLink)
    {
        List<BaseFriendLink> list = baseFriendLinkService.selectBaseFriendLinkList(baseFriendLink);
        ExcelUtil<BaseFriendLink> util = new ExcelUtil<BaseFriendLink>(BaseFriendLink.class);
        util.exportExcel(response, list, "友情链接数据");
    }

    /**
     * 获取友情链接详细信息
     */
    @PreAuthorize("@ss.hasPermi('webshop:BaseFriendLink:query')")
    @GetMapping(value = "/{linkId}")
    public AjaxResult getInfo(@PathVariable("linkId") Long linkId)
    {
        return success(baseFriendLinkService.selectBaseFriendLinkByLinkId(linkId));
    }

    /**
     * 新增友情链接
     */
    @PreAuthorize("@ss.hasPermi('webshop:BaseFriendLink:add')")
    @Log(title = "友情链接", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseFriendLink baseFriendLink)
    {
        return toAjax(baseFriendLinkService.insertBaseFriendLink(baseFriendLink));
    }

    /**
     * 修改友情链接
     */
    @PreAuthorize("@ss.hasPermi('webshop:BaseFriendLink:edit')")
    @Log(title = "友情链接", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseFriendLink baseFriendLink)
    {
        return toAjax(baseFriendLinkService.updateBaseFriendLink(baseFriendLink));
    }

    /**
     * 删除友情链接
     */
    @PreAuthorize("@ss.hasPermi('webshop:BaseFriendLink:remove')")
    @Log(title = "友情链接", businessType = BusinessType.DELETE)
	@DeleteMapping("/{linkIds}")
    public AjaxResult remove(@PathVariable Long[] linkIds)
    {
        return toAjax(baseFriendLinkService.deleteBaseFriendLinkByLinkIds(linkIds));
    }
}
